package diploma.kisel.modelas.service;

import java.util.List;

import diploma.kisel.modelas.domain.Program;
import diploma.kisel.modelas.domain.ProgramType;
import diploma.kisel.modelas.repository.ProgramRepositoryImpl;
import diploma.kisel.modelas.repository.api.ProgramRepository;
import diploma.kisel.modelas.service.api.ProgramService;

public class ProgramServiceImpl implements ProgramService {

	private ProgramRepository programRepository = new ProgramRepositoryImpl();

	@Override
	public List<Program> findAll() {
		return programRepository.findAll();
	}

	@Override
	public List<Program> findByPrice(int minPrice, int maxPrice) {
		return programRepository.findByPrice(minPrice, maxPrice);
	}

	@Override
	public Program findById(int id) {
		if (id >= 0)
			return programRepository.findByid(id);
		else
			return null;
	}

	@Override
	public Program save(Program program) {
		if (program != null) {
			if (program.getId() != null)
				return programRepository.update(program);
			else
				return programRepository.save(program);
		}
		return null;
	}

	@Override
	public void remove(Program program) {
		if (program != null && program.getId() != null)
			programRepository.remove(program);

	}

	@Override
	public void remove(int id) {
		Program program = findById(id);
		remove(program);

	}

	@Override
	public List<Program> findByPriceAndType(int minPrice, int maxPrice,
			ProgramType type) {
		return programRepository.findByPriceAndType(minPrice, maxPrice, type);
	}

}
